#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <aclconio.h>
#include <define.h>
#include <transact.h>
#include <tran.h>
#include <gds.h>
#include <sizes.h>
#include "ConfProto.h"
#include "tblutil.h"
#include <\SOFTPAY\Ver30\source\include\sizes.h>
#include <\SOFTPAY\Ver30\HostSrc\citisrc\citiids.h>
#include <\SOFTPAY\Ver30\HostSrc\cpacsrc\cpacids.h>
#include <confio.h>

#include <\SOFTPAY\Ver30\source\include\BDT.h>



static void *storeFromStruct;

static int recordNum;
void registerBDT(void *ptr)
{
	 storeFromStruct = ptr;
}

void *dealWithAddressBoundary(void*address);
int	inLoadBDTRecFromStruct (int inRecNumber, void *vdStruct)
{
	int inRet;
	char* tmp = (char*)vdStruct;

	registerBDT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inLoadConfRec(BDT_FILENAME, SIZE_BDT_REC, inRecNumber, vdStruct);

	recordNum = inRecNumber;
	return inRet;
}

void vdRestoreBDTRecFromStruct(void *vdStruct)
{
	registerBDT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	memcpy((char *) pvdGetBDTRec(), vdStruct, SIZE_BDT_REC);

}

void vdCopyBDTRecFromStruct(void *vdStruct)
{
	registerBDT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
		memcpy(vdStruct, (char *) pvdGetBDTRec(), SIZE_BDT_REC);

}

int	inSaveBDTRecFromStruct (int inRecNumber,  void *vdStruct)
{
	int inRet;

	registerBDT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(BDT_FILENAME, SIZE_BDT_REC, inRecNumber, (char *) vdStruct);

	return inRet;
}

int	inUpdateBDTRecFromStruct (void *vdStruct)
{
	int inRet;

	registerBDT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(BDT_FILENAME, SIZE_BDT_REC, recordNum, (char *) vdStruct);

	return inRet;
}

long lnGetNbrOfTransactionsFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return lnGetNbrOfTransactions();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->lnNbrOfTransactions;
}

void vdSetNbrOfTransactionsFromStruct(long lnNbrOfTransactions, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetNbrOfTransactions(lnNbrOfTransactions);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((BDT_REC*)vdStruct)->lnNbrOfTransactions = lnNbrOfTransactions;
}

short inGetBatchNumSizeFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetBatchNumSize();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->inBatchNumSize;
}

void vdSetBatchNumSizeFromStruct(short inBatchNumSize, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetBatchNumSize(inBatchNumSize);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((BDT_REC*)vdStruct)->inBatchNumSize = inBatchNumSize;
}

short inGetBatchNumLimitFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetBatchNumLimit();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->inBatchNumLimit;
}

void vdSetBatchNumLimitFromStruct(short inBatchNumLimit, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetBatchNumLimit(inBatchNumLimit);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((BDT_REC*)vdStruct)->inBatchNumLimit = inBatchNumLimit;
}

char* szGetLastTransactionDateFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetLastTransactionDate();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->szLastTransactionDate;
}

void vdSetLastTransactionDateFromStruct(const char* szLastTransactionDate, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetLastTransactionDate(szLastTransactionDate);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((BDT_REC*)vdStruct)->szLastTransactionDate, szLastTransactionDate, sizeof(((BDT_REC*)NULL)->szLastTransactionDate)-1);
}

char* szGetLastTransactionTimeFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetLastTransactionTime();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->szLastTransactionTime;
}

void vdSetLastTransactionTimeFromStruct(const char* szLastTransactionTime, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetLastTransactionTime(szLastTransactionTime);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((BDT_REC*)vdStruct)->szLastTransactionTime, szLastTransactionTime, sizeof(((BDT_REC*)NULL)->szLastTransactionTime)-1);
}

long lnGetNbrOfOfflineTranFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return lnGetNbrOfOfflineTran();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->lnNbrOfOfflineTran;
}

void vdSetNbrOfOfflineTranFromStruct(long lnNbrOfOfflineTran, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetNbrOfOfflineTran(lnNbrOfOfflineTran);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((BDT_REC*)vdStruct)->lnNbrOfOfflineTran = lnNbrOfOfflineTran;
}

VS_BOOL fGetBDTCustomBit1FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetBDTCustomBit1();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->fBDTCustomBit1;
}

void vdSetBDTCustomBit1FromStruct(VS_BOOL fBDTCustomBit1, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetBDTCustomBit1(fBDTCustomBit1);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((BDT_REC*)vdStruct)->fBDTCustomBit1 = fBDTCustomBit1;
}

VS_BOOL fGetBDTCustomBit2FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetBDTCustomBit2();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->fBDTCustomBit2;
}

void vdSetBDTCustomBit2FromStruct(VS_BOOL fBDTCustomBit2, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetBDTCustomBit2(fBDTCustomBit2);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((BDT_REC*)vdStruct)->fBDTCustomBit2 = fBDTCustomBit2;
}

VS_BOOL fGetBDTCustomBit3FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetBDTCustomBit3();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->fBDTCustomBit3;
}

void vdSetBDTCustomBit3FromStruct(VS_BOOL fBDTCustomBit3, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetBDTCustomBit3(fBDTCustomBit3);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((BDT_REC*)vdStruct)->fBDTCustomBit3 = fBDTCustomBit3;
}

VS_BOOL fGetBDTCustomBit4FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetBDTCustomBit4();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->fBDTCustomBit4;
}

void vdSetBDTCustomBit4FromStruct(VS_BOOL fBDTCustomBit4, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetBDTCustomBit4(fBDTCustomBit4);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((BDT_REC*)vdStruct)->fBDTCustomBit4 = fBDTCustomBit4;
}

VS_BOOL fGetDoNotUploadOfflinePairTransVoidFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetDoNotUploadOfflinePairTransVoid();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->fDoNotUploadOfflinePairTransVoid;
}

void vdSetDoNotUploadOfflinePairTransVoidFromStruct(VS_BOOL fDoNotUploadOfflinePairTransVoid, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetDoNotUploadOfflinePairTransVoid(fDoNotUploadOfflinePairTransVoid);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((BDT_REC*)vdStruct)->fDoNotUploadOfflinePairTransVoid = fDoNotUploadOfflinePairTransVoid;
}

VS_BOOL fGetTipAsANewRegisterInBatchFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetTipAsANewRegisterInBatch();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->fTipAsANewRegisterInBatch;
}

void vdSetTipAsANewRegisterInBatchFromStruct(VS_BOOL fTipAsANewRegisterInBatch, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetTipAsANewRegisterInBatch(fTipAsANewRegisterInBatch);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((BDT_REC*)vdStruct)->fTipAsANewRegisterInBatch = fTipAsANewRegisterInBatch;
}

VS_BOOL fGetAllTransAsANewRegisterInBatchFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetAllTransAsANewRegisterInBatch();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->fAllTransAsANewRegisterInBatch;
}

void vdSetAllTransAsANewRegisterInBatchFromStruct(VS_BOOL fAllTransAsANewRegisterInBatch, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetAllTransAsANewRegisterInBatch(fAllTransAsANewRegisterInBatch);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((BDT_REC*)vdStruct)->fAllTransAsANewRegisterInBatch = fAllTransAsANewRegisterInBatch;
}

VS_BOOL fGetStoreTrack1FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetStoreTrack1();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->fStoreTrack1;
}

void vdSetStoreTrack1FromStruct(VS_BOOL fStoreTrack1, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetStoreTrack1(fStoreTrack1);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((BDT_REC*)vdStruct)->fStoreTrack1 = fStoreTrack1;
}

VS_BOOL fGetStoreTrack2FromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetStoreTrack2();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->fStoreTrack2;
}

void vdSetStoreTrack2FromStruct(VS_BOOL fStoreTrack2, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetStoreTrack2(fStoreTrack2);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((BDT_REC*)vdStruct)->fStoreTrack2 = fStoreTrack2;
}

VS_BOOL fGetStoreCustNameFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetStoreCustName();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((BDT_REC*)vdStruct)->fStoreCustName;
}

void vdSetStoreCustNameFromStruct(VS_BOOL fStoreCustName, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetStoreCustName(fStoreCustName);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((BDT_REC*)vdStruct)->fStoreCustName = fStoreCustName;
}

